package restfuljobs

import static org.grails.jaxrs.response.Responses.*

import javax.ws.rs.Consumes
import javax.ws.rs.GET
import javax.ws.rs.Produces
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.QueryParam
import javax.ws.rs.POST
import javax.ws.rs.core.Response

@Path('/api/jobApplication')
@Consumes(['application/xml','application/json'])
@Produces(['application/xml','application/json'])
class JobApplicationCollectionResource {

    def jobApplicationResourceService
    
    @POST
    Response create(JobApplication dto) {
        created jobApplicationResourceService.create(dto)
    }

    @GET
    Response readAll(@QueryParam("userId") Long userId) {
    
    	if (!userId) {
    		throw new AccessDeniedException(JobApplication.class, userId)
    	}
    	
        ok jobApplicationResourceService.readAll(userId)
    }
    
    @Path('/{id}')
    JobApplicationResource getResource(@PathParam('id') Long id) {
        new JobApplicationResource(jobApplicationResourceService: jobApplicationResourceService, id:id)
    }
        
}
